$(function () {
    var bannerid = $.getUrlParam('bannerid')
    // 页面初始化...数据数据回显...
    getBannerInfo( bannerid );

    // 将从后天获取到的信息回显到页面当中....
    function getBannerInfo(bannerId)
    {
        $.ajax({
            async: false,
            type: 'post',
            headers: {"Accept-CMS-Token": token},
            url: getbanner,
            data: {
                bannerId: bannerId,
            },
            dataType: 'json',
            success:successFn,
            error: function () {
                console.log('根据id查看banner失败...')
            }
        })
    };

    // 当发送ajax成功的时候,执行下面的函数...
    function successFn(data)
    {
        $('input[name = title]').val(data.value.title);//标题



        for( var i=0;i<$('input[name = type]').length;i++ )
        {
            if($('input[name = type]').eq(i).val() == data.value.type )
            {
                $('input[name = type]').eq(i).attr('checked','true');
            }
        };//类型
        $('textarea[name = info]').val(data.value.info);//简介
        $('.start_time').val( formatUsualStamp(data.value.startTime) );//上线时间
        $('#hidden_starttime').val( formatUsualStamp(data.value.startTime) )
        $('.end_time').val( formatUsualStamp(data.value.endTime) );//下线时间
        $('#hidden_endtime').val( formatUsualStamp(data.value.endTime) )
        $('.setImg img').attr('src',address + data.value.coverUrl);//封面图片
        $('.setImg img').attr('height',300);
        $('input[name = coverUrl]').val(data.value.coverUrl);

        if( data.value.imageUrl != '' )
        {//回显imageUrl..
            $('input[name = imageUrl]').val(data.value.imageUrl);
            var imageArr = data.value.imageUrl.split(',')

            for( var j=0;j<imageArr.length;j++ )
            {
                $('.image_div p.upsuccess').append('<img src="'+address + imageArr[j]+'" url="'+imageArr[j]+'">');
            };

        };
        if( data.value.cssUrl != '' )
        {//回显cssUrl
            $('input[name = cssUrl]').val( data.value.cssUrl );
            var cssArr = data.value.cssUrl.split(',');

            for( var x = 0;x<cssArr.length;x++ )
            {
                $('.css_div').append('<p class="upsuccess clearFloat" url="'+cssArr[x]+'"><span class="fr">上传成功!</span> <span class="true_url">' + cssArr[x] + '</span></p>');
            };

        };
        if( data.value.jsUrl != '' )
        {//回显jsUrl
            $('input[name = jsUrl]').val( data.value.jsUrl );
            var jsArr = data.value.jsUrl.split(',');

            for( var y = 0;y<jsArr.length;y++ )
            {
                $('.js_div').append('<p class="upsuccess clearFloat" url="'+jsArr[y]+'"><span class="fr">上传成功!</span> <span class="true_url">' + jsArr[y] + '</span></p>');
            };

        };
        if( data.value.jsUrl != '' )
        {//回显htmlUrl
            $('input[name = htmlUrl]').val( data.value.htmlUrl );
            var htmlArr = data.value.htmlUrl.split(',');

            for( var z = 0;z<htmlArr.length;z++ )
            {
                $('.html_div').append('<p class="upsuccess clearFloat" url="'+htmlArr[z]+'"><span class="preSee fr">预览</span><span class="fr">上传成功!</span> <span class="true_url">' + htmlArr[z] + '</span></p>');
            };

        };
        $('textarea[name = staticUrl]').val( data.value.staticUrl)

        console.log('根据id查看banner成功...')

    };

    // 点击预览...在浏览器中打开一个新标签去预览这个上传的页面...
    $(document).on('click','span.preSee',function () {

        var html_url_str = $(this).parent().children('span.true_url').html()
        // console.log( html_url_str )
        window.open( address + html_url_str );

    });


});
